// $codepro.audit.disable numericLiterals
/**
 * Tests methods inside the ShipYard class
 */
package javamonsters.tests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.awt.Point;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

import javamonsters.model.InventoryItem;
import javamonsters.model.Marketplace;
import javamonsters.model.Planet;
import javamonsters.model.Player;
import javamonsters.model.Ship;
import javamonsters.model.ShipYard;
import javamonsters.model.SolarSystem;
import javamonsters.model.TradeGood;
import javamonsters.model.SolarSystem.Attributes;
import javamonsters.model.SolarSystem.TechLevels;



import org.junit.Test;



/**
 * ShipYardTest class for testing buyShip() method
 * @author Ying
 * @version 1.0
 */
public class ShipYardTest {
	


	
	/**
	 * Runs JUnit test for testBuyShip method
	 */
	@Test // $codepro.audit.disable disallowTestAnnotation
	public void testBuyShip() {
		final SolarSystem system = new SolarSystem("Sol", new Point(0, 0),
				TechLevels.MEDIEVAL, Attributes.ARTISTIC);
		
		final Planet planet = new Planet(system, "Sol");
		
		final ShipYard shipyard = new ShipYard(planet);
		
		final Marketplace market = planet.getMarketplace();
		
		final Ship playerShip = new Ship(Ship.ShipType.FLEA);
		
		final TradeGood water = TradeGood.WATER;
		
		final TradeGood food = TradeGood.FOOD;
		
		final BigDecimal waterPrice = market.calculatePrice(water);
		
		final BigDecimal foodPrice = market.calculatePrice(food);
		
		final InventoryItem waterItem = new InventoryItem(waterPrice, 1);
		
		final InventoryItem foodItem = new InventoryItem(foodPrice, 1);
		
		final Map<TradeGood,InventoryItem> sellMap = 
				new HashMap<TradeGood, InventoryItem>(); 
		
		market.setSellMap(sellMap);
		
		sellMap.put(water, waterItem);
		sellMap.put(food, foodItem);
		
		System.out.println("water price: " + waterPrice);
		System.out.println("food price: " + foodPrice);
		
		playerShip.addCargo(water, 1);
		playerShip.addCargo(food, 1);

		final Ship shipToBuy = new Ship(Ship.ShipType.GNAT);
		
		final Player player = new Player("Ying", 14, 2, 0, 0, 
				new BigDecimal(4000), playerShip, "normal");
		
		final BigDecimal finalCredits2 = player.getCredits()
				.subtract(new BigDecimal(shipToBuy.getPrice()));
		
		final BigDecimal finalCredits = finalCredits2.add(waterPrice).add(foodPrice);
		
		System.out.println("final credits: " + finalCredits);
		
		shipyard.setCurrentCharacter(player);
		shipyard.buyShip(shipToBuy);
		
		System.out.println("player credits: " + player.getCredits());
		
		assertTrue("ship type is GNAT", player.getShip().getShipType()
		     	   .equals(Ship.ShipType.GNAT ));
		assertTrue("player's current ship equals the ship bought",
				   player.getShip().equals(shipToBuy));
		assertEquals("player's current credits equal final credits",
				    player.getCredits(), finalCredits);
		
	}
	
	/** 
	 * toString method for ShipYardTest class
	 * @return an empty String
	 */
	public String toString() {
		return "";
	}

}

